<template>
  <div class="dashboard">
    <div class="dashboard-header">
      <h1>欢迎来到AI角色扮演世界</h1>
      <p>选择你喜欢的角色，开始一段奇妙的对话之旅</p>
    </div>
    
    <div class="stats-cards">
      <el-row :gutter="20">
        <el-col :span="8">
          <el-card class="stat-card">
            <div class="stat-content">
              <div class="stat-icon">
                <el-icon size="40" color="#409eff"><Avatar /></el-icon>
              </div>
              <div class="stat-info">
                <h3>{{ totalRoles }}</h3>
                <p>可用角色</p>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="stat-card">
            <div class="stat-content">
              <div class="stat-icon">
                <el-icon size="40" color="#67c23a"><ChatDotRound /></el-icon>
              </div>
              <div class="stat-info">
                <h3>{{ chatSessions }}</h3>
                <p>聊天会话</p>
              </div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="8">
          <el-card class="stat-card">
            <div class="stat-content">
              <div class="stat-icon">
                <el-icon size="40" color="#e6a23c"><Star /></el-icon>
              </div>
              <div class="stat-info">
                <h3>{{ favoriteRoles }}</h3>
                <p>收藏角色</p>
              </div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
    
    <div class="quick-actions">
      <h2>快速开始</h2>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-card class="action-card" @click="goToRoles">
            <div class="action-content">
              <el-icon size="60" color="#409eff"><Avatar /></el-icon>
              <h3>浏览角色</h3>
              <p>探索各种有趣的AI角色</p>
            </div>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card class="action-card" @click="goToChat">
            <div class="action-content">
              <el-icon size="60" color="#67c23a"><ChatDotRound /></el-icon>
              <h3>开始聊天</h3>
              <p>与AI角色进行对话</p>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useRoleStore } from '@/stores/role'

const router = useRouter()
const roleStore = useRoleStore()

const totalRoles = ref(0)
const chatSessions = ref(0)
const favoriteRoles = ref(0)

onMounted(async () => {
  try {
    await roleStore.fetchRoleList({ page: 1, pageSize: 1 })
    totalRoles.value = roleStore.total
  } catch (error) {
    console.error('获取角色数量失败:', error)
  }
})

const goToRoles = () => {
  router.push('/roles')
}

const goToChat = () => {
  router.push('/chat')
}
</script>

<style scoped>
.dashboard {
  padding: 30px;
  max-width: 1200px;
  margin: 0 auto;
}

.dashboard-header {
  text-align: center;
  margin-bottom: 40px;
}

.dashboard-header h1 {
  color: #333;
  font-size: 32px;
  margin-bottom: 10px;
  font-weight: 600;
}

.dashboard-header p {
  color: #666;
  font-size: 16px;
}

.stats-cards {
  margin-bottom: 40px;
}

.stat-card {
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s;
}

.stat-card:hover {
  transform: translateY(-4px);
}

.stat-content {
  display: flex;
  align-items: center;
  gap: 20px;
}

.stat-icon {
  flex-shrink: 0;
}

.stat-info h3 {
  font-size: 28px;
  color: #333;
  margin: 0 0 5px 0;
  font-weight: 600;
}

.stat-info p {
  color: #666;
  margin: 0;
  font-size: 14px;
}

.quick-actions h2 {
  color: #333;
  margin-bottom: 20px;
  font-size: 24px;
  font-weight: 600;
}

.action-card {
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.3s;
  height: 200px;
}

.action-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.action-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
}

.action-content h3 {
  color: #333;
  margin: 15px 0 10px 0;
  font-size: 20px;
  font-weight: 600;
}

.action-content p {
  color: #666;
  margin: 0;
  font-size: 14px;
}

:deep(.el-card__body) {
  padding: 20px;
}
</style>
